package com.dream.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * 概要:
 *
 * @Author:匠人码农
 * @Date:2021/02/04 23:21
 */
public class HibernateUtils {
    // 创建全局单一sessionFactory对象
    private static final SessionFactory sessionFacoty = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
            return new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory(){
        return sessionFacoty;
    }
}
